﻿@inject IStringLocalizer<DialogEmail> Localizer

<div class="input-group">
    <BootstrapInput PlaceHolder="@Localizer["EmailInput"]" Value="@InputValue" />
    <Button Icon="fa-regular fa-address-card" OnClick="@OnEmailButtonClick" />
</div>

@code {
    [Inject]
    [NotNull]
    private DialogService? DialogService { get; set; }

    private IEnumerable<string> Emails { get; set; } = Array.Empty<string>();

    private string? InputValue { get; set; }

    private async Task OnEmailButtonClick()
    {
        var result = await DialogService.ShowModal<ResultDialogDemo2>(new ResultDialogOption()
        {
            Title = Localizer["EmailDialogTitle"],
            BodyContext = new ResultDialogDemo2.FooContext() { Count = 10, Emails = InputValue },
            ButtonYesText = Localizer["EmailDialogButtonYes"],
            ButtonYesIcon = "fa-solid fa-magnifying-glass",
            ComponentParamters = new Dictionary<string, object>
            {
                [nameof(ResultDialogDemo2.Emails)] = Emails,
                [nameof(ResultDialogDemo2.EmailsChanged)] = EventCallback.Factory.Create<IEnumerable<string>>(this, v => Emails = v)
            }
        });

        if (result == DialogResult.Yes)
        {
            InputValue = string.Join(";", Emails);
        }
    }
}
